|
1
|
|
|
let num = 0; |
|
2
|
|
|
|
|
3
|
|
|
const REDUCER_KEYS = { |
|
4
|
|
|
BulkActions: 'bulkaction', |
|
5
|
|
|
DataSource: 'dataSource', |
|
6
|
|
|
Editor: 'editor', |
|
7
|
|
|
ErrorHandler: 'errorhandler', |
|
8
|
|
|
Grid: 'grid', |
|
9
|
|
|
Loader: 'loader', |
|
10
|
|
|
Menu: 'menu', |
|
11
|
|
|
Pager: 'pager', |
|
12
|
|
|
Selection: 'selection' |
|
13
|
|
|
}; |
|
14
|
|
|
|
|
15
|
|
|
export const generateLastUpdate = () => ++num; |
|
16
|
|
|
|
|
17
|
|
|
export const resetLastUpdate = () => { num = 0; }; |
|
18
|
|
|
|
|
19
|
|
|
export const getLastUpdate = (store, key, reducerKeys = REDUCER_KEYS) => { |
|
20
|
|
|
|
|
21
|
|
|
if (typeof reducerKeys === 'string') { |
|
22
|
|
|
const state = store.getState().get |
|
23
|
|
|
? store.getState().get(reducerKeys) |
|
24
|
|
|
: store.getState()[reducerKeys]; |
|
25
|
|
|
|
|
26
|
|
|
return updateGetter( |
|
27
|
|
|
state, |
|
28
|
|
|
REDUCER_KEYS, |
|
29
|
|
|
Object.keys(REDUCER_KEYS), |
|
30
|
|
|
key |
|
31
|
|
|
); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
const dynamicReducerKeys = typeof reducerKeys === 'object' |
|
35
|
|
|
&& Object.keys(reducerKeys).length > 0 |
|
36
|
|
|
? reducerKeys |
|
37
|
|
|
: REDUCER_KEYS; |
|
38
|
|
|
|
|
39
|
|
|
return updateGetter( |
|
40
|
|
|
store.getState(), |
|
41
|
|
|
dynamicReducerKeys, |
|
42
|
|
|
Object.keys(dynamicReducerKeys), |
|
43
|
|
|
key |
|
44
|
|
|
); |
|
45
|
|
|
}; |
|
46
|
|
|
|
|
47
|
|
|
export const updateGetter = (state, reducerKeys, keys, key) => |
|
48
|
|
|
keys.reduce((prev, reducerAccessor) => { |
|
49
|
|
|
const reducerKey = reducerKeys[reducerAccessor]; |
|
50
|
|
|
const stateMap = (typeof state.get === 'function') |
|
51
|
|
|
? state.get(reducerKey) |
|
52
|
|
|
: state[reducerKey]; |
|
53
|
|
|
if (stateMap && stateMap.toJS) { |
|
54
|
|
|
prev[reducerKey] = stateMap.getIn([key, 'lastUpdate']); |
|
55
|
|
|
} |
|
56
|
|
|
else if (typeof stateMap === 'object' && stateMap[key]) { |
|
57
|
|
|
prev[reducerKey] = stateMap[key].lastUpdate; |
|
58
|
|
|
} |
|
59
|
|
|
return prev; |
|
60
|
|
|
}, {}); |
|
61
|
|
|
|